package com.idna.batchid.domain;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Map.Entry;

import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;

public class RecordMapper implements FieldSetMapper<Record>
{

	@Override
	public Record mapFieldSet(FieldSet fieldSet)
	{
		Record record = new Record();
		Properties props = fieldSet.getProperties();
		Map<String,String> map = new HashMap<String, String>();	

		for(Entry<Object, Object> entry:props.entrySet())
		{
			if(!map.containsKey((String)entry.getKey()))
			{
				map.put((String)entry.getKey(), (String)entry.getValue());
			}
		}
		
		record.setRecord(map);
		
		return record;
	}

}
